package ch05_类与对象;

public class VarArgsDemo {
	int getMax(int first, int ...varArgs) {
		int max=first;
		for(int i:varArgs) {
			max=i>max?i:max;
		}
		return max;
	}
	public static void main(String[] args) {
		int[] a= {6,4,5,9,8,7};
		VarArgsDemo demo=new VarArgsDemo();
		System.out.println("max(1)="+demo.getMax(1));
		System.out.println("max(2,1)="+demo.getMax(2, 1));
		System.out.println("max(6,4,5,9,8,7)="+demo.getMax(6, 4,5,9,8,7));
		System.out.println("max(a[])="+demo.getMax(a[0],a));
	}
}
